/**
 * @file   1026.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Wed Jul 14 19:18:54 2021
 * 
 * @brief  PAT advanced 1026:Queueing
 * 
 * 
 */
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
typedef struct athletes{
    int arriving;
    int dure;
    int beginning;
    bool isvip;
}Athlete;
void form(int a){
    int h=a/3600;
    a=a-h*3600;
    int m=a/60;
    int s=a-60*m;
    if(h<10){
	cout<<"0";
    }
    cout<<h<<":";
    if(m<10){
	cout<<"0";
    }
    cout<<m<<":";
    if(s<10){
	cout<<"0";
    }
    cout<<s;
}
void output(int a,int b){
    form(a);
    cout<<" ";
    form(b);
    cout<<" ";
    int d=(b-a)/60;
    if(b-a-60*d>=30){
	d++;
    }
    cout<<d<<endl;
}
int findmin(const vector<int>& isavailable,int time){
    int flag=0;
    int min=isavailable[0];
    for(int i=0;i<isavailable.size();i++){
	if(isavailable[i]<=time){
	    return i;
	}
    }
    for(int i=0;i<isavailable.size();i++){
	if(isavailable[i]<min){
	    min=isavailable[i];
	    flag=i;
	}
    }
    return flag;
};
int nextone(const int& order,const vector<bool>& playornot){
    for(int i=order;i<playornot.size();i++){
	if(playornot[i]==false){
	    return i;
	}
    }
    return playornot.size();
};
bool cmp(Athlete& A,Athlete& B){
    return (A.arriving<B.arriving);
}
bool cmp2(Athlete& A,Athlete& B){
    return (A.beginning<B.beginning);
}
int trans(int a,int b,int c){
    return (3600*a+60*b+c);
}
int findVIP(const vector<Athlete>& ath,const vector<bool>& playornot,int time){
    for(int i=0;i<ath.size();i++){
	if(ath[i].arriving<=time&&playornot[i]==false&&ath[i].isvip==true){
	    return i;
	}
	if(ath[i].arriving>time){
	    break;
	}
    }
    return -1;
};
class Solution{
private:
    vector<Athlete> ath;
    vector<bool> playornot;//Mark whether a custom get the field.
    int tablenum;
    int athletenum;
    map<int,bool> viptable;
    vector<int> isavailable;
    vector<int> servers;//Mark # of serve customs
public:
    Solution();
    void solve();
    void print();
};
Solution::Solution(){
    cin>>athletenum;
    for(int i=0;i<athletenum;i++){
	int h,m,s,arriving,dure;
	bool isvip;
	scanf("%d:%d:%d",&h,&m,&s);
	arriving=trans(h,m,s);
	cin>>dure;
	cin>>isvip;
	Athlete A;
	A.arriving=arriving;
	A.dure=dure*60;
	A.isvip=isvip;
	ath.push_back(A);
	playornot.push_back(false);
    }
    cin>>tablenum;
    int vipnum;
    cin>>vipnum;
    for(int i=0;i<tablenum;i++){
	viptable[i]=false;
	isavailable.push_back(0);//0 represents available!
	servers.push_back(0);
    }
    for(int i=0;i<vipnum;i++){
	int d;
	cin>>d;
	viptable[d-1]=true;
    }
    sort(ath.begin(),ath.end(),cmp);
}
void Solution::solve(){
    int servenums=0;
    int ordered=0;
    while(servenums<athletenum){
	int d=nextone(ordered,playornot);
	int index=findmin(isavailable,ath[d].arriving);
	if(isavailable[index]==0){//This table is EMPTY!
	    //Register the earliest one!
	    ordered=nextone(ordered,playornot);
	    ath[ordered].beginning=ath[ordered].arriving;
	    isavailable[index]=ath[ordered].beginning+ath[ordered].dure;
	    playornot[ordered]=true;
	    if(ath[ordered].beginning<=75600){
		servers[index]++;
	    }
	}else{//NOT EMPTY!
	    if(viptable[index]==false){//case 2.1: This table isn't VIP table
		ordered=nextone(ordered,playornot);
		ath[ordered].beginning=max(ath[ordered].arriving,isavailable[index]);
		isavailable[index]=ath[ordered].beginning+ath[ordered].dure;
		playornot[ordered]=true;
		if(ath[ordered].beginning<=75600){
		    servers[index]++;
		}
	    }else{//case 2.2:VIP table!
		int V;
		V=findVIP(ath,playornot,isavailable[index]);//-1 means NOT FOUND!
		if(V!=-1){
		    ath[V].beginning=isavailable[index];
		    isavailable[index]=ath[V].beginning+ath[V].dure;
		    playornot[V]=true;
		    if(ath[V].beginning<=75600){
			servers[index]++;
		    }
		}else{//NO VIP
		    ordered=nextone(ordered,playornot);
       		    ath[ordered].beginning=max(ath[ordered].arriving,isavailable[index]);
		    isavailable[index]=ath[ordered].beginning+ath[ordered].dure;
		    playornot[ordered]=true;
		    if(ath[ordered].beginning<=75600){
			servers[index]++;
		    }
		}
	    }
	}
	servenums++;
    }
}
void Solution::print(){
    sort(ath.begin(),ath.end(),cmp2);
    for(int i=0;i<ath.size();i++){
	if(ath[i].beginning<=75600){
	    output(ath[i].arriving,ath[i].beginning);
	}
    }
    cout<<servers[0];
    for(int i=1;i<servers.size();i++){
	cout<<" "<<servers[i];
    }
    cout<<endl;
}
int main(){
    Solution S;
    S.solve();
    S.print();
}
